/* eslint-disable no-param-reassign */
/* eslint-disable max-lines */
import * as BASE from '@/stores/definitions-base';
import { DatePicker, DatePicker2, Input, Switch } from '@alifd/next';
import { t } from '@lingui/macro';
import React from 'react';

const {
  DATETIME_TEXT,
  DATE_TEXT,
  TIME_TEXT,
  EMPTY_TEXT,
  ENUMS: ENUMSBase,
  FieldsGrid: FieldGridBase,
  TitleGrid,
  column: columnBase,
  toSelectDataSource,
} = BASE;
export { DATETIME_TEXT, DATE_TEXT, EMPTY_TEXT, TIME_TEXT, TitleGrid, toSelectDataSource };

export function column(...args) {
  return columnBase(orderModel, ...args);
}

export function FieldsGrid(props) {
  return <FieldGridBase model={orderModel} {...props} />;
}

//----------------------------------------------------------------------
export const ENUMS = {
  ...ENUMSBase,
  orderType: {
    0: t`OPEN票`,
    1: t`普通票`,
    undefined: t`普通票`,
  },
  roundTripText: {
    [true]: t`往返`,
    [false]: t`单程`,
    undefined: t`单程`,
  },
  roundTrip: {
    0: t`单程`,
    1: t`往返`,
  },
  orderStatus: {
    0: t`已取消`,
    1: t`未乘车`,
    2: t`已乘车`,
    3: t`已完成`,
    4: t`状态未知`,
    5: t`已过期`,
  },
  orderFromType: {
    0: t`微信`,
    1: t`后台`,
    2: t`H5下单`,
  },
  payType: {
    0: t`微信`,
    1: t`支付宝`,
  },
  //  0-已取消 1-未乘车 2-已乘车 3-已完成 4-其他 5-已过期
  ticketStatus: {
    0: t`已取消`,
    1: t`未乘车`,
    2: t`已乘车`,
    3: t`已完成`,
    4: t`状态未知`,
    5: t`已过期`,
    6: t`已改签`,
  },
  returnTrip: {
    0: t`去程`,
    1: t`回程`,
    undefined: t`去程`,
  },
  currency: {
    RMB: t`人民币`,
    HKD: t`港币`,
    MOP: t`澳门币`,
  },
  state: {
    '-1': '已取消',
    0: '已驳回',
    1: '申请中',
    2: '已提交',
  },
  type: {
    0: '车票类型',
    1: '取消订单',
    2: '其他类型',
  },
};

export const orderModel = {
  report: {
    label: t`报备第三方`,
    ui: {
      renderer: (v, r) => <Switch disabled={global?.getEnvCfg()?.companies.ZL.id == r?.busOrder?.companyId} checked={v} unCheckedChildren="否" checkedChildren="是" autoWidth />,
    },
  },
  cancelCoupon: {
    label: t`是否取消卡券`,
    ui: {
      renderer: (v, r) => <Switch checked={v} disabled={JSON.stringify(r.discountInfos) === '[]'} unCheckedChildren="否" checkedChildren="是" autoWidth />,
    },
  },
  enableProfitShare: {
    label: '是否开启分账',
    ui: {
      renderer: (v) => <Switch checked={v} unCheckedChildren="否" checkedChildren="是" autoWidth />,
    },
  },
  pendingSettlementAmount: {
    label: '待分账金额',
    // text: (v) => <span>{(v / 100).toFixed(2)}</span>,
  },
  settledAmount: {
    label: '已分账金额（单位：分）',
  },
  refundedAmount: {
    label: '已退款金额',
  },
  discountPrice: {
    label: t`优惠金额`,
    ui: {
      renderer: (v) => <span>{v}</span>,
    },
  },
  actualPrice: {
    label: '实付价格',
    ui: {
      renderer: (v) => <span>{v}</span>,
    },
  },
  contributionAmount: {
    label: '本次退款出资金额',
    ui: {
      renderer: (v) => <span>{v / 100}</span>,
    },
  },
  refundPrice: {
    label: '退款金额',
  },
  ticketRefunds: [{
    label: '该出资方涵盖车票及对应金额',
    ticketCode: {
      label: '车票号',
    },
    refundPrice: {
      label: '退款金额',
    },
  }],
  targetType: {
    label: '帐户类型<br/> 由调用方根据分账方身份类型定义，例如：COMPANY,PARTNER,CHANNEL等',
  },
  targetId: {
    label: 'targetType下的帐户标识',
  },
  targetName: {
    label: '帐户名',
  },
  refundRemark: {
    label: t`申请退款说明`,
    ui: {
      renderer: (v) => <Input.TextArea value={v} />,
    },
  },
  refundTime: {
    label: t`实际退款时间`,
    text: DATETIME_TEXT,
    ui: {
      renderer: (v) => <DatePicker style={{ width: '100%' }} type="datetime" showTime value={DATETIME_TEXT(v)} />,
    },
  },
  distanceTime: {
    label: t`距离发车时长`,
    ui: {
      renderer: (v) => <span style={{ color: 'blue', fontWeight: 450, fontSize: 15 }}>{v}</span>,
    },
  },
  attachments: [{
    label: t`附件`,
    title: {
      label: t`附件标题`,
    },
    description: {
      label: t`附件说明`,
    },
    binaryId: [{
      label: t`附件id`,
    }],
  }],
  partnerName: {
    label: t`合伙人姓名`,
  },
  orderNumber: {
    label: t`订单编号`,
  },
  hotel: {
    label: t`关联酒店`,
  },
  hotelPrice: {
    label: t`酒店价格`,
  },
  hotelRootPrice: {
    label: t`酒店基础价`,
  },
  taskIds: [{
    label: t`任务关联id`,
  }],
  completionTime: {
    label: t`完成时间`,
  },
  orderChangeRemarks: {
    label: t`订单变更备注`,
  },
  username: {
    label: t`操作人账号`,
  },
  busOrder: {
    label: t`巴士订单`,
    orderStatus: {
      label: t`订单状态 0-已取消 1-已支付 2-已完成 3-其他`,
    },
    payTime: {
      label: t`支付时间`,
    },
    payType: {
      label: t`支付方式，0 - 微信支付 , 1 - 支付宝`,
    },
    appId: {
      label: t`appid`,
    },
    orderFromType: {
      label: t`订单来源 0 - 微信 , 1 - 后台下单`,
    },
    cancelOrderTime: {
      label: t`取消订单时间`,
    },
    cancelRemark: {
      label: t`取消订单备注`,
    },
    refundTime: {
      label: t`退款时间`,
    },
    refundPrice: {
      label: t`退款金额（退给用户的）`,
    },
    settlementRatio: {
      label: t`退款结算比例`,
    },
    refundRemark: {
      label: t`退款备注`,
    },
    orderId: {
      label: t`第三方公司对应订单id`,
    },
    cost: {
      label: t`与公司结算价格`,
    },
    companyId: {
      label: t`公司id`,
    },
    directionalCompany: {
      label: t`定向公司id`,
    },
    companyName: {
      label: t`公司名称`,
    },
    agent: {
      label: t`代理商`,
    },
    effTime: {
      label: t`有效时间`,
    },
    from: {
      label: t`去程开始信息`,
      city: {
        label: t`城市（字典项id）`,
      },
      station: {
        label: t`站点id`,
      },
      stationName: {
        label: t`站点名称`,
      },
      onAddress: {
        label: t`详细上车站点地址`,
      },
      offAddress: {
        label: t`详细下车站点地址`,
      },
    },
    to: {
      label: t`去程结束信息`,
      city: {
        label: t`城市（字典项id）`,
      },
      station: {
        label: t`站点id`,
      },
      stationName: {
        label: t`站点名称`,
      },
      onAddress: {
        label: t`详细上车站点地址`,
      },
      offAddress: {
        label: t`详细下车站点地址`,
      },
    },
    returnFrom: {
      label: t`回程开始信息`,
      city: {
        label: t`城市（字典项id）`,
      },
      station: {
        label: t`站点id`,
      },
      stationName: {
        label: t`站点名称`,
      },
      onAddress: {
        label: t`详细上车站点地址`,
      },
      offAddress: {
        label: t`详细下车站点地址`,
      },
    },
    returnTo: {
      label: t`回程结束信息`,
      city: {
        label: t`城市（字典项id）`,
      },
      station: {
        label: t`站点id`,
      },
      stationName: {
        label: t`站点名称`,
      },
      onAddress: {
        label: t`详细上车站点地址`,
      },
      offAddress: {
        label: t`详细下车站点地址`,
      },
    },
    isOpen: {
      label: t`去程是否open票`,
    },
    returnIsOpen: {
      label: t`回程是否open票`,
    },
    isRoundTrip: {
      label: t`是否往返票`,
    },
    collectorName: {
      label: t`取票人名称`,
    },
    collectorPhone: {
      label: t`取票人电话`,
    },
    partnerId: {
      label: t`合伙人id(如果是扫合伙人的码进来的则需要把信息带上不是则为空)`,
    },
    fullname: {
      label: t`下单人姓名(平台用户),不传则使用当前登录人`,
    },
    username: {
      label: t`下单人(平台用户),不传则使用当前登录人`,
    },
    phone: {
      label: t`下单人电话(平台用户),不传则使用当前登录人`,
    },
    currencyId: {
      label: t`币种`,
    },
    shift: {
      label: t`去程班次信息`,
      date: {
        label: t`去程日期 发车日期`,
      },
      companyId: {
        label: t`公司id`,
      },
      companyName: {
        label: t`公司名称`,
      },
      scheduleId: {
        label: t`班次id`,
      },
    },
    returnShift: {
      label: t`回程班次信息`,
      date: {
        label: t`去程日期 发车日期`,
      },
      companyId: {
        label: t`公司id`,
      },
      companyName: {
        label: t`公司名称`,
      },
      scheduleId: {
        label: t`班次id`,
      },
    },
    priceType: {
      label: t`价格应用界面（目前wechat方式购票传递wechat，其他的传递传空值或者不传。）`,
    },
    prices: [{
      label: '班次下票种价格枚举',
      fee: {
        label: '价格',
      },
      isReturn: {
        label: '单双程0：单，1：双',
      },
      lawTicketType: {
        label: '价格级别',
      },
      priceId: {
        label: '票价 id',
      },
      stdPrivFlg: {
        label: '票价类型 0 优惠 、1 标准',
      },
      ticketCategoryId: {
        label: '路线票种 ID 确定票种，票价类型 票类及价格（包括币种）',
      },
      ticketCategoryName: {
        label: '票种名称',
      },
      ticketType: {
        label: '票价类型名称',
      },
      ticketTypeId: {
        label: '票种类型id',
      },
      ticketCategoryLineId: {
        label: '路线票种id',
      },
    }],
    orderDetails: {
      label: '订单车票每程详情列表',
      passenger: {
        // (如果没有选择乘客这里的数据填 ZAKC)
        label: t`乘客姓名`,
      },
      passengerTel: {
        label: t`乘客联系电话(如果没有选择乘客这里的数据填 12345678900)`,
      },
      refundPrice: {
        label: t`车票退款金额`,
        ui_table: {
          renderer: (v) => <Input value={v} />,
        },
      },
      serviceCharge: {
        label: t`手续费`,
      },
      firstChangePrice: {
        label: t`真实优惠`,
      },
      ticketPrice: {
        label: t`原票价`,
      },
      originalPrice: {
        label: t`原票价`,
      },
      busTicketType: {
        label: '票种类型（必填）',
      },
      ticketCategoryLineId: {
        label: '线路票种价格（必填）',
      },
      passengerEmail: {
        label: '电子邮箱（可不填）',
      },
      passengerFlightNo: {
        label: '航班号码（可不填）',
      },
      idCard: {
        label: '身份证号（可不填）',
      },
      directorIdType: {
        label: '身份证类型（可不填）',
      },
      isReturn: {
        label: '是否回程 0：去程，1：回程',
      },
      price: {
        label: '票价',
      },
      priceId: {
        label: '关联价格定义中的标识',
      },
      relatedTicket: {
        label: '关联回程票号与回程, 回程取票后填写在此处',
      },
      busScheduleId: {
        label: '预定班次编号',
      },
      shiftTime: {
        label: '预定班次时间',
        text: DATETIME_TEXT,
      },
      runDate: {
        label: '行程日期',
      },
      runTime: {
        label: '行程时间',
      },
      checkIn: {
        label: '上车班次信息',
        busScheduleId: {
          label: '实际班次编号',
        },
        checkInTime: {
          label: '上车时间',
        },
        ticketChecker: {
          label: '验票员',
        },
      },
      //  0-状态未知 1-新票未售 2-已售未取 3-已取未用<br/> 5-已乘车扫描未转乘 6-已扫描 7-车票已过期 8-车票已停用 9-车票已作废 10-已退票
      operatingState: {
        label: '第三方状态',
      },
      state: {
        label: '状态',
        text: (v) => ENUMS.ticketStatus[v],
      },
      ignore: {
        label: '是否忽略<br/> - false 不忽略，不在申请退款中且中港通已退款则会显示在申请取消列表中<br/> - true 忽略',
      },
      stateName: {
        label: '状态名称',
      },
      ticketCode: {
        label: '车票号',
      },
      takeTicketCode: {
        label: '取票号',
      },
      seats: {
        label: '座位号',
      },
      cancelTime: {
        label: '客户申请取消时间',
      },
      account: {
        label: '分账方信息',
      },
    },
    remarks: {
      label: t`备注信息`,
    },
    consoleRemarks: {
      label: t`控制台备注信息`,
    },
  },
  transactionId: {
    label: t`微信支付订单号`,
  },
  prepayId: {
    label: t`微信预支付生成的标识<br/> 首次发起支付时生成，支付过程中断后再次支付时提供`,
  },
  price: {
    label: t`订单原价`,
    ui: {
      renderer: (v) => <span>{v}</span>,
    },
  },
  currency: {
    label: t`币种<br/> - RMB<br/> - HKD<br/> - MOP`,
  },
  orderType: {
    label: t`订单类型<br/> - 1 包车订单<br/> - 2 班车订单<br/> - 3 巴士订单`,
  },
  relation: {
    label: t`关联订单<br/> 记录发起返空线路的原订单。不为空则表示为特惠订单。`,
  },
  notices: [{
    label: '通知控制信息<br/> 第二次将不发送通知',
  }],
  settlementId: {
    label: t`结算id`,
  },
  unfrozenFunds: {
    label: t`是否解冻资金`,
  },
  closingOfDistribution: {
    label: t`是否分账结束`,
  },
  accountRequestInfos: [{
    label: '分账请求信息列表',
    appId: {
      label: 'appId',
    },
    id: {
      label: '订单id',
    },
    transactionId: {
      label: '微信支付订单号',
    },
    outOrderNo: {
      label: '商户系统内部的分账单号',
    },
    orderId: {
      label: '微信分账单号,微信支付系统返回的唯一标识',
    },
    state: {
      label: '分账单状态（每个接收方的分账结果请查看receivers中的result字段）<br/> 1、PROCESSING：处理中<br/> 2、FINISHED：分账完成',
    },
    receivers: [{
      label: '分账方信息列表',
      type: {
        label: '分账接收方类型<br/> 1、MERCHANT_ID：商户号<br/> 2、PERSONAL_OPENID：个人openid（由父商户APPID转换得到）',
      },
      description: {
        label: '分账的原因描述，分账账单中需要体现',
      },
      account: {
        label: '分账接收方账号：<br/> 1、类型是MERCHANT_ID时，是商户号（mch_id或者sub_mch_id）<br/> 2、类型是PERSONAL_OPENID时，是个人openid',
      },
      username: {
        label: '合伙人 / 公司 / 司机',
      },
      name: {
        label: '合伙人名 / 公司名 / 司机',
      },
      userType: {
        label: '身份 1-合伙人 2-公司 3-司机',
      },
      amount: {
        label: '分账金额 单位为分，只能为整数，不能超过原订单支付金额及最大分账比例金额',
      },
      result: {
        label: '分账结果<br/> 1、PENDING：待分账<br/> 2、SUCCESS：分账成功<br/> 3、CLOSED：已关闭',
      },
      failReason: {
        label: '分账失败原因，当分账结果result为CLOSED（已关闭）时，返回该字段<br/> 1、ACCOUNT_ABNORMAL：分账接收账户异常<br/> 2、NO_RELATION：分账关系已解除<br/> 3、RECEIVER_HIGH_RISK：高风险接收方<br/> 4、RECEIVER_REAL_NAME_NOT_VERIFIED：接收方未实名<br/> 5、NO_AUTH：分账权限已解除<br/> 6、RECEIVER_RECEIPT_LIMIT：接收方已达收款限额<br/> 7、PAYER_ACCOUNT_ABNORMAL：分出方账户异常',
      },
      detailId: {
        label: '微信分账明细单号',
      },
      inflowPlatform: {
        label: '这笔资金是否放回平台',
      },
      redistribute: {
        label: '重新分账信息',
        outOrderNo: {
          label: '商户系统内部的分账单号',
        },
        orderId: {
          label: '微信分账单号,微信支付系统返回的唯一标识',
        },
        state: {
          label: '分账单状态（每个接收方的分账结果请查看receivers中的result字段）<br/> 1、PROCESSING：处理中<br/> 2、FINISHED：分账完成',
        },
        result: {
          label: '分账结果<br/> 1、PENDING：待分账<br/> 2、SUCCESS：分账成功<br/> 3、CLOSED：已关闭',
        },
        failReason: {
          label: '分账失败原因，当分账结果result为CLOSED（已关闭）时，返回该字段',
        },
        detailId: {
          label: '微信分账明细单号',
        },
      },
    }],
  }],
  refundInfos: [{
    label: '退款信息集合',
    applicationId: {
      label: '申请编号<br/> S + 年月日 + 自增编号',
    },
    state: {
      label: '申请状态<br/> - 0 已驳回<br/> - 1 申请中<br/> - 2 已提交<br/> 前端提交',
    },
    refundId: {
      label: '退款流水号',
    },
    type: {
      label: '退款类型<br/> - 0 车票类型<br/> - 1 取消订单<br/> - 2 其他类型',
    },
    distanceTime: {
      label: '距离时间',
    },
    cancelTime: {
      label: '申请取消时间',
    },
    refundPrice: {
      label: '申请退款金额',
    },
    cancelRemark: {
      label: '申请说明',
    },
    rejectRemark: {
      label: '驳回说明',
    },
    rejectTime: {
      label: '驳回时间',
    },
    attachments: [{
      label: '附件',
      title: {
        label: '附件标题',
      },
      description: {
        label: '附件说明',
      },
      binaryId: [{
        label: '附件id',
      }],
    }],
    ticketRefundInfos: [{
      label: '车票退款信息',
      ticketCode: {
        label: '车票号',
      },
      originalPrice: {
        label: '原票价',
      },
      ticketPrice: {
        label: '原票价',
      },
      operatingState: {
        label: '第三方状态',
      },
      state: {
        label: '车票状态',
      },
      refundPrice: {
        label: '退款金额',
      },
      operatorRefundTime: {
        label: '运营商退款时间',
      },
    }],
  }],
  crBy: {
    label: t`创建者`,
  },
  upBy: {
    label: t`最后修改者`,
  },
  crDate: {
    label: t`创建时间`,
  },
  upDate: {
    label: t`最后修收时间`,
  },
  tenantId: {
    label: t`租户ID`,
  },
  id: {
    label: '',
  },
  applicationId: {
    label: t`申请编号`,
  },
  // <br/> - 0 已驳回<br/> - 1 申请中<br/> - 2 已提交<br/> 前端提交
  state: {
    label: t`申请状态`,
    text: (v) => ENUMS.state[v],
  },
  refundId: {
    label: t`退款流水号`,
  },
  // <br/> - 0 车票类型<br/> - 1 取消订单<br/> - 2 其他类型
  type: {
    label: t`退款类型`,
    text: (v) => ENUMS.type[v],
  },
  refunded: {
    label: t`是否退款<br/> - false 未退款<br/> - true 已退款`,
  },
  cancelTime: {
    label: t`申请取消时间`,
    text: DATETIME_TEXT,
    ui: {
      renderer: (v) => <DatePicker2 style={{ width: '100%' }} outputFormat={DATETIME_TEXT} showTime value={v} />,
      itemProps: { required: true },
    },
  },
  cancelRemark: {
    label: t`申请说明`,
    ui: {
      renderer: (v) => <Input.TextArea value={v} />,
      span: 2,
      itemProps: { required: true },
    },
  },
  rejectRemark: {
    label: t`驳回说明`,
  },
  rejectTime: {
    label: t`驳回时间`,
  },
  orderInfo: {
    label: t`关联订单信息`,
    orderId: {
      label: t`订单id`,
    },
    orderType: {
      label: t`订单类型：1-包车订单 2-班车订单 3-巴士订单`,
    },
    orderTime: {
      label: t`出行时间`,
    },
    name: {
      label: t`下单人名称`,
    },
  },
  ticketRefundInfos: [{
    label: t`车票退款信息`,
    ticketCode: {
      label: t`车票号`,
    },
    isReturn: {
      label: t`是否回程 0：去程，1：回程`,
    },
    originalPrice: {
      label: t`原票价`,
    },
    ticketPrice: {
      label: t`原票价`,
    },
    operatingState: {
      label: t`第三方状态`,
    },
    state: {
      label: t`车票状态`,
    },
    refundPrice: {
      label: t`退款金额`,
    },
    operatorRefundPrice: {
      label: t`中港通退款金额`,
    },
    operatorRefundTime: {
      label: t`运营商退款时间`,
    },
    shiftTime: {
      label: t`预计上车时间`,
      text: DATETIME_TEXT,
    },
  }],
};

